/*
 * $Id$
 */
package py.windmill.web;

import java.util.ArrayList;
import java.util.List;
import py.windmill.action.ActionSupport;
import py.windmill.action.Request;
import py.windmill.action.Resolution;
import py.windmill.action.ValidationErrors;
import py.windmill.resolution.Tiles;
import py.windmill.resolution.TilesMap;
import py.windmill.validation.Required;

/**
 *
 * @author myang
 */
public class DictionaryAction extends ActionSupport {

    @Override
    public Object onGet(final Request req) {
        return req.param("word") + "[" + req.getInt("idx") + "]";
    }

    @Override
    public ValidationErrors validate(final Request req) {
        return validate(req, "word", new Required());
    }

    @Override
    public String boundTo() {
        return "/dict/{word}[{idx=0}]";
    }

    @Override
    public List<Resolution> produces() {
        final List<Resolution> resolutions = new ArrayList();
        resolutions.add(new Tiles() {
            @Override
            public TilesMap prepare(final Request req, final Object val) {
                req.attr("word", val);
                return new TilesMap().put("body", "dict.jsp");
            }

            @Override
            public TilesMap prepare(final Request req, 
                                    final ValidationErrors errors) {
                req.attr("error", errors);
                return new TilesMap().put("body", "dict.jsp");
            }
        });

        resolutions.addAll(super.produces());
        return resolutions;
    }

    
    
}
